default_platform :mac

platform :mac do

  ############################ PRE ############################

  before_all do
  end

  ######################## SETUP LANES ########################

  desc "Setup development"
  lane :setup do
  end

  desc "Setup release developer id account settings. (only use admin)"
  lane :setup_release_id do
    # Update Project Team
    update_project_team(
      path: "Clipy.xcodeproj",
      teamid: "BBCHAJ584H"
    )
    # Update Provisioning Profile
    update_provisioning_profile_specifier(
      xcodeproj: "Clipy.xcodeproj",
      new_specifier: "ClipyDistribution",
      configuration: "Release",
      target: "^Clipy$"
    )
  end

  ####################### PUBLIC LANES ########################

  desc "Runs all the tests"
  lane :test do
    slack(message: "Start Testing")
    scan_clipy
    slack(message: "Passed All Tests")
  end
  
  desc "Release"
  lane :release do
    # TODO: Use :codesigning_identity options (Developer ID Application: Shunsuke Furubayashi (BBCHAJ584H))
    # TODO: Use :export_method options (developer-id)
  end

  ####################### PRIVATE LANES ########################

  private_lane :scan_clipy do
    scan(
      workspace: "Clipy.xcworkspace",
      scheme: "Clipy",
      skip_build: true,
      verbose: true,
      clean: true
    )
  end

  ############################ POST ############################

  after_all do |lane|
  end

  error do |lane, exception|
    if lane == :scan_clipy
      slack(
        message: "Failed Tests: " + ENV['FL_REPORT_PATH'],
        success: false
      )
    end
  end
end
